<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\admin\model;

use app\models\BaseModel;
use think\Exception;
use think\Model;

class BaoxiaoCycleModel extends BaseModel
{

    protected $type = [
        'more' => 'array',
    ];

    /**
     * @param $page
     * @param $limit
     * @return array|\PDOStatement|string|\think\Collection|\think\model\Collection
     */
    public function getList($page,$limit){
        try {
            $where= [];
            return $this->where($where)->limit(($page-1)*$limit,$limit)->order('id desc')->select();
        }catch (Exception $exception){
            $this->setErrorInfo($exception->getMessage());
        }
    }

    /**
     * 获取报销周期
     */
    public static function getListAll()
    {
        try {
            return self::order('id desc')->field('id,name')->select();
        }catch (\Exception $exception){
            self::setErrorInfo($exception->getMessage());
        }

    }

    /**
     * 获取报销周期
     * @param $id
     * @return array|\PDOStatement|string|Model|null
     */
    public static function getInfo($id)
    {
        try {
            return self::where('id',$id)->find();
        }catch (\Exception $exception){
            self::setErrorInfo($exception->getMessage());
        }
    }

    /**
     * 编辑信息
     * @param $id
     * @param $data
     * @return BaoxiaoCycleModel
     */
    public function edit($id,$data)
    {
        return $this->update($data,['id'=>$id]);
    }

    /**
     * 更改状态
     * @param $cycle_id
     * @param $status
     * @return int|string
     */
    public static function statusOperate($cycle_id,$status)
    {
        return self::where('id',$cycle_id)->setField('status',$status);
    }

    /**
     * 获取进行中信息
     * @return array|\PDOStatement|string|Model|null
     */
    public static function getIngCycle()
    {
        try {
            return self::where('status',1)->find();
        }catch (\Exception $exception){
            self::setErrorInfo($exception->getMessage());
        }
    }

    /**
     * 获取进行中数量
     * @return float|int|string
     */
    public static function getIngCount()
    {
        return self::where('status',1)->count();
    }


}